package com.xywang.service.role;

import com.xywang.dao.BaseDao;
import com.xywang.dao.role.RoleDao;
import com.xywang.dao.role.RoleDaoImpl;
import com.xywang.pojo.Role;
import org.junit.Test;

import java.sql.Connection;
import java.util.List;

public class RoleServiceImpl implements RoleService{
    private RoleDao roleDao;
    public RoleServiceImpl() {
        this.roleDao=new RoleDaoImpl();
    }

    // 获取角色列表
    @Override
    public List<Role> getRoleListService() {
        Connection connection=null;
        List<Role> roleListDao=null;
        try {
            connection = BaseDao.getConnection();
            roleListDao = roleDao.getRoleListDao(connection);
        } catch (Exception e) {
            e.printStackTrace();
        }finally{
            BaseDao.closeResource(connection,null,null);
        }
        return roleListDao;
    }
    @Test
    public void test(){
        RoleService roleService = new RoleServiceImpl();
        List<Role> roleListService = roleService.getRoleListService();
        for (Role r : roleListService) {
            System.out.println(r.getRoleName()+" "+r.getId());
        }
    }
}
